import { request } from 'umi';
import type { ImagesListItem, ImagesListParams } from './data';

export type ResponesParams = {
  data: ImagesListItem[];
  success: boolean;
};

export async function queryFiles(params?: ImagesListParams) {
  return request<ResponesParams>('/api/file', {
    params,
  });
}

export async function addFile(params: ImagesListParams) {
  return request('/api/file', {
    method: 'POST',
    data: {
      ...params,
      method: 'add',
    },
  });
}

export async function uploadFile(params: ImagesListParams, file: FormData) {
  return request('/api/upload', {
    method: 'POST',
    data: {
      ...params,
      file,
    },
  });
}

export async function queryImages(params?: ImagesListParams) {
  return request('/api/images', {
    params,
  });
}

export async function addImages(params: ImagesListParams) {
  return request('/api/images', {
    method: 'POST',
    data: {
      ...params,
      method: 'add',
    },
  });
}

export async function updateImages(params: ImagesListParams) {
  return request('/api/images', {
    method: 'POST',
    data: {
      ...params,
      method: 'update',
    },
  });
}

export async function deleteImages(params: { id: string }) {
  return request('/api/images', {
    method: 'POST',
    data: {
      ...params,
      method: 'delete',
    },
  });
}
